package syn;

import java.util.concurrent.locks.ReentrantLock;

public class LockDemo
{


    public static void main(String[] args)
    {
        testLock lock = new testLock();
        testLock lock2 = new testLock();
        new Thread(lock).start();
        new Thread(lock).start();

    }

}

class testLock implements Runnable
{
    //定义可重复锁
    private final ReentrantLock rlock = new ReentrantLock();

    int tickNum = 10;

    public void run()
    {
        while (true)
        {
//            rlock.lock();
            try
            {
                if (tickNum > 0)
                {
                    try
                    {
                        Thread.sleep(100);
                    } catch (InterruptedException e)
                    {
                        e.printStackTrace();
                    }
                    System.out.println(tickNum--);
                } else
                {
                    break;
                }

            } finally
            {
//                rlock.unlock();
            }
        }
    }
}
